﻿Imports Phila
Imports Phila.Sql
Imports Phila.CommonClasses

Public Class EditPages
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not IsPostBack = True Then
            If Not Request.QueryString("id") Is Nothing Then
                fillData(Request.QueryString("id"))
            End If
        End If
    End Sub

    Private Sub fillData(ByVal Id As Integer)
        Dim arr As Array
        arr = RetriveData("SELECT [Name] ,[Summary] ,[Description] ,[MetaTitle] ,[MetaKeywords] ,[MetaDescription] ,[IsActive] ,[Vieworder] FROM ptn_Pages where Id=" & Id, 7)
        txtName.Text = Server.HtmlDecode(arr(0))
        'radSummary.Html = arr(1)
        txtDescription.Content = Server.HtmlDecode(arr(2))
        txtMTitle.Text = Server.HtmlDecode(arr(3))
        txtMKeywords.Text = Server.HtmlDecode(arr(4))
        txtMDescription.Text = Server.HtmlDecode(arr(5))
        chkIsActive.Checked = arr(6)
        txtViewOrder.Text = arr(7)
    End Sub

    Protected Sub btnSave_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSave.Click
        Try
            Dim chkActive As String
            If chkIsActive.Checked = True Then
                chkActive = "1"
            Else
                chkActive = "0"
            End If
            If Request.QueryString("id") Is Nothing Then
                Insert_Update_Delete_Record("INSERT INTO ptn_Pages ([Name] ,[Description] ,[MetaTitle] ,[MetaKeywords] ,[MetaDescription] ,[IsActive] ,[Vieworder]) VALUES ('" & Server.HtmlEncode(txtName.Text.Replace("'", "&#039;")) & "','" & txtDescription.Content.Replace("'", "&#039;") & "' ,'" & Server.HtmlEncode(txtMTitle.Text.Replace("'", "&#039;")) & "' ,'" & Server.HtmlEncode(txtMKeywords.Text.Replace("'", "&#039;")) & "' ,'" & Server.HtmlEncode(txtMDescription.Text.Replace("'", "&#039;")) & "' ," & chkActive & " ," & Server.HtmlEncode(txtViewOrder.Text.Replace("'", "&#039;")) & ")")
            Else
                Insert_Update_Delete_Record("Update ptn_Pages set [Name]='" & Server.HtmlEncode(txtName.Text.Replace("'", "&#039;")) & "',[Description]='" & txtDescription.Content.Replace("'", "&#039;") & "' ,[MetaTitle]='" & Server.HtmlEncode(txtMTitle.Text.Replace("'", "&#039;")) & "' ,[MetaKeywords]='" & Server.HtmlEncode(txtMKeywords.Text.Replace("'", "&#039;")) & "' ,[MetaDescription]='" & Server.HtmlEncode(txtMDescription.Text.Replace("'", "&#039;")) & "' ,[IsActive]=" & chkActive & " ,[Vieworder]=" & Server.HtmlEncode(txtViewOrder.Text.Replace("'", "&#039;")) & " where Id=" & Request.QueryString("Id"))
            End If
            Response.Redirect("ViewPages.aspx")
        Catch ex As Exception
            Throw ex
        End Try
    End Sub

    Protected Sub btnCancel_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnCancel.Click
        Response.Redirect("ViewPages.aspx")
    End Sub


End Class